package com.company.jdk.stream;

import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author yingfing
 * @create 2020--10--03 22:44
 * @describe
 */
public class TestStream {
    public static void main(String[] args) {
        // 5 种创建 Stream 的方式
        /**
         * Arrays.stream()
         * Stream.of()
         * Collection.stream()  Set\List\Map
         * Stream.generate()
         * Stream.iterate()
         */

        // Arrays = Array Tools         Array
        // Collections = Collection Tools Collectioin
        int i = Arrays.binarySearch(new int[]{1, 2, 3, 4, 5, 6}, 5);// 数组需要有序
        Arrays.sort(new int[]{1, 2, 3, 4, 5, 6});
        List<Integer> integerList = Arrays.asList(1, 2, 3, 4, 5, 6);

        List<Integer> collection = new ArrayList<>();
        collection.add(3);
        collection.add(2);
        collection.add(1);
        Collections.sort(collection);
        Integer max = Collections.max(collection);

        // 1.Arrays.stream()
        IntStream stream = Arrays.stream(new int[]{1, 2, 3, 4, 5, 6});

        // 2.Stream.of()
        Stream<Integer> stream1 = Stream.of(1, 2, 3, 4, 5, 6, 7);

        // 3.Stream.generate()
        Stream<Integer> generate = Stream.generate(() -> (int) (Math.random() * 100));

        // 4. Stream.iterate()
        Stream<Integer> iterate = Stream.iterate(0, x -> x + 1);
        iterate.forEach(System.out::println);

        // 5. Collection -> List/Set/SortedSet/Map
        // 因为stream()不是static,不能使用Collection类名直接调用,需要使用"实例名"进行调用
        Collection cc = new ArrayList();
        Stream stream2 = cc.stream();
        Collection cc1 = new HashSet();
        Stream stream3 = cc1.stream();
    }
}
